package main

import (
	"fmt"
	"sync"
)

//互斥锁
var x int64
var lock sync.Mutex
var wx sync.WaitGroup

func add() {
	for i := 0; i < 500; i++ {
		lock.Lock()
		x += 1
		lock.Unlock()
	}
	wx.Done()
}

func main() {
	wx.Add(2)
	go add()
	go add()
	wx.Wait()
	fmt.Println(x)
}
